package com.igeek.health.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.igeek.health.constant.MessageConstant;
import com.igeek.health.entity.Setmeal;
import com.igeek.health.result.Result;
import com.igeek.health.service.ISetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author fengqq
 * @Description TODO
 * @Date 2024/9/10  16:27
 */
@RestController
@RequestMapping("/app/setmeal")
@Api(tags = "套餐模块的控制层")
@CrossOrigin //处理跨越问题
public class SetmealController {
    @Autowired
    private ISetmealService setmealService;

    @GetMapping("/findAll")
    @ApiOperation("套餐列表显示")
    public Result findAll(){
        List<Setmeal> list = setmealService.list();
        if(CollectionUtil.isNotEmpty(list)){
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,list);
        }
        return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
    }

    @GetMapping("/{id}")
    @ApiOperation("套餐详情显示")
    public Result findOne(@PathVariable("id") Integer id){
        Setmeal setmeal = setmealService.findOneDetail(id);
        if(setmeal!=null){
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        }
        return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
    }
}
